package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryNestedVo;
import com.spzx.product.api.domain.vo.CategoryVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @author Haoran Sun
 * @since 2024/07/23
 */

@Component
public class RemoteCategoryFallbackFactory implements FallbackFactory<RemoteCategoryService> {


    private static final Logger log = LoggerFactory.getLogger(RemoteCategoryFallbackFactory.class);

    @Override
    public RemoteCategoryService create(Throwable cause) {
        log.error("获取分类列表失败:{}", cause.getMessage());
        return new RemoteCategoryService() {
            @Override
            public R<List<CategoryVo>> getOneCategory(String source) {
                return R.fail("获取一级分类列表失败");
            }
            @Override
            public R<List<CategoryNestedVo>> tree(String source) {
                return R.fail("获取全部分类列表失败");
            }
        };

    }
}
